Learn T-SQL Commands with Samples
Skip Navigation Links
Skip Navigation Links.
Expand DatabaseDatabase
Expand TableTable
Expand ViewView
Expand Stored ProcedureStored Procedure
Expand Data FilteringData Filtering
Expand Data GroupingData Grouping
Expand JoinsJoins
Expand TriggerTrigger
Expand CursorCursor
Expand OperatorsOperators
Expand ConstraintsConstraints
Collapse FunctionsFunctions
Expand Conditional ProcessingConditional Processing
Expand LoopingLooping
Expand Error HandlingError Handling
Expand v.IMP Queriesv.IMP Queries
Expand XMLXML
Expand Query PerformanceQuery Performance
Expand QueriesQueries
Expand NormalizationNormalization
Expand CreateCreate
     

String Functions

 
SELECT

      Name,
      LEFT(Name,3)      as	'Left',
      RIGHT(Name,2)     as	'Right',
      LOWER(Name)       as	'Lower',
      UPPER(Name)       as	'Upper',
      REVERSE(Name)     as	'Reverse',
      REPLICATE(Name,2) as	'Replicate',
      QUOTENAME(Name)   as	'QuoteName',
      LEN(Name)         as	'Length',
      LTRIM(Name)       as	'LTrim',
      RTRIM(Name)       as	'RTrim',

      SUBSTRING(Name,2,3)         as	'Substring',
      REPLACE(Name,'i','e')       as	'Replace',
      Name + SPACE(3) +  Country  as 	'Space'

FROM EMP
    
      
Output
Name Left Right Lower Upper Reverse Replicate QuoteName Length LTrim RTrim SubString Replace Space
Vijay Vij ay vijay VIJAY yajiV VijayVijay [Vijay] 5 Vijay Vijay ija Vejay Vijay India
Bill Bil ll bill BILL lliB BillBill [Bill] 4 Bill Bill ill Bell Bill USA
Kris Kri is kris KRIS sirK KrisKris [Kris] 4 Kris Kris ris Kres Kris France